<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>
        <div>
            <table>
                <tr>
                    <th>
                        姓名:
                    </th>
                    <th>
                        <input type="text" placeholder="请输入姓名" name="BName">
                    </th>
                </tr>
                <tr>
                    <th>
                        性别
                    </th>
                    <th>
                        <input type="text" placeholder="性别" name="Sex">
                    </th>

                </tr>
                <tr>
                    <th>
                        班级
                    </th>
                    <th>
                        <input type="text" placeholder="班级" name="ClassName">
                    </th>
                </tr>
                <tr>
                    <th>
                        <input type="button" value="保存" onclick="save()">
                        <input type="button" value="取消" onclick="cancel()">
                    </th>
                </tr>
            </table>
        </div>
    </div>
    <script src="./jquery-3.6.0.min.js"></script>
    <script src="./baseurl.js"></script>
    <script src="./js.js"></script>
    <script>
        $(function () {
            let id = getUrlParam('id');
            id = id || 0;
            getlistclass(id).then(res => {
                let obj = res.data;
                console.log(obj);
                $('[name=BName]').val(obj.CName);
                $('[name=Sex]').val(obj.Sex);
                $('[name=ClassName]').val(obj.ClassName);

            })
        })
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
        function save() {
            let id = getUrlParam('id')
            let obj = {
                CName: $('[name=BName]').val(),
                Sex: $('[name=Sex]').val(),
                ClassName: $('[name=ClassName]').val()
            }
            upclassblog(id,obj).then(
                res=>{
                    location.href='./class.html?id=' +id
                }
            )
        }
        function cancel(){
            let id =getUrlParam('id')
            location.href='./class.html?id=' +id
        }
    </script>
</body>

</html>